package cn.lili.timetask.handler.impl.redpack;

import cn.lili.modules.member.client.RedPackUserClient;
import cn.lili.modules.member.entity.dos.RedPackUser;
import cn.lili.timetask.handler.EveryDayExecute;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

@Slf4j
@Component
@RequiredArgsConstructor
public class RedPackUserEveryDayExecute implements EveryDayExecute {

    private final RedPackUserClient redPackUserClient;

    @Override
    public void execute() {
        List<RedPackUser> redPackUserList = redPackUserClient.getListByLastTime();
        if (!redPackUserList.isEmpty()) {
            redPackUserList.forEach(redPackUser -> {
                redPackUser.setRedPackCount(0);
                redPackUserClient.updateById(redPackUser);
            });
        }
    }
}